package com.mt.grand.singleton.register;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * 登记式单例模式不论是普通map还是并发map并发量大的时候还是存在线程不安全。需要继续关注此问题。
 */
public class RegistSingletonTest {

    public static void main(String[] args) throws IOException {
        int count = 700;
        final CountDownLatch countDownLatch = new CountDownLatch(count);

        for(int i=0;i<count;i++){
            new Thread(new Runnable() {
                public void run() {
                    try {
                        countDownLatch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(RegistSingleton.getInstance(RegistSingleton.class.getName()));
                }
            }).start();
            countDownLatch.countDown();
        }

        System.in.read();
    }
}